package bb.lanxing.lib.devices.core.sync;

public abstract class AbstractSyncPresenter implements SyncPresenter {
    protected SyncHelper syncHelper;

    protected abstract SyncHelper createSyncHelper();

    @Override
    public abstract Class<? extends SyncService> getSyncService();

    public void destroy() {
        unbindSyncService(isSynchronising());
        this.syncHelper = null;
    }

    @Override
    public void bindSyncService() {
        SyncHelper syncHelper = this.syncHelper;
        if (syncHelper == null) {
            syncHelper = createSyncHelper();
        }
        this.syncHelper = syncHelper;
        if (syncHelper != null) {
            syncHelper.bindSyncService(getContext());
        }
    }

    @Override
    public void unbindSyncService(boolean z) {
        SyncHelper syncHelper = this.syncHelper;
        if (syncHelper != null) {
            syncHelper.unbindSyncService(getContext(), z);
        }
    }

    @Override
    public void requestFiles() {
        SyncManager syncManager = getSyncManager();
        if (syncManager != null) {
            syncManager.readFileList();
        }
    }

    @Override
    public boolean isSynchronising() {
        SyncHelper syncHelper = this.syncHelper;
        return syncHelper != null && syncHelper.isSynchronising();
    }

    @Override
    public SyncManager getSyncManager() {
        SyncHelper syncHelper = this.syncHelper;
        if (syncHelper != null) {
            return syncHelper.getSyncManager();
        }
        return null;
    }
}
